﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class formMain : Form
    {
        public formMain()
        {
            InitializeComponent();
        }

        private void bacsiBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.bacsiBindingSource.EndEdit();            
            this.tableAdapterManager.UpdateAll(this.hospitalDataSet);

        }

        private void Form2_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'hospitalDataSet.bacsi' table. You can move, or remove it, as needed.
            this.bacsiTableAdapter.Fill(this.hospitalDataSet.bacsi);

        }

        private void bacsiDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {

        }

        private void bacsiBindingNavigator_RefreshItems(object sender, EventArgs e)
        {

        }

        private void ribbonButton1_Click(object sender, EventArgs e)
        {
            
        }

        private void bindingNavigatorMoveLastItem_Click(object sender, EventArgs e)
        {

        }

        private void ribbonButton2_Click(object sender, EventArgs e)
        {
            Form2 FormAdd = new Form2(this.hospitalDataSet);
            FormAdd.Show();
        }

        private void ribbonButton9_Click(object sender, EventArgs e)
        {
            try
            {
                this.Validate();
                this.bacsiBindingSource.EndEdit();
                this.bacsiTableAdapter.Update(this.hospitalDataSet.bacsi);                                
                MessageBox.Show("Lưu dữ liệu thành công");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Cập nhật dữ liệu bị lỗi");
            }
        }

        private void ribbonButton10_Click(object sender, EventArgs e)
        {            
            Int32 selectedRowCount = bacsiDataGridView.Rows.GetRowCount(DataGridViewElementStates.Selected);            
            if (selectedRowCount > 0)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();

                for (int i = 0; i < selectedRowCount; i++)
                {
                    sb.Append("Row: ");
                    sb.Append(bacsiDataGridView.SelectedRows[i].Index.ToString());
                    sb.Append(Environment.NewLine);
                }

                sb.Append("Total: " + selectedRowCount.ToString());
                MessageBox.Show(sb.ToString(), "Selected Rows");
            }
        }

        private void ribbonButton3_Click(object sender, EventArgs e)
        {            
            foreach (DataRow editRow in this.hospitalDataSet.bacsi.Rows)
            {
                if ((int)editRow["id"]==2)
                {
                    editRow["sodienthoai"] = "0123456789";
                }
            }
        }

        private void ribbonButton4_Click(object sender, EventArgs e)
        {
            int index=this.bacsiDataGridView.CurrentCell.RowIndex;
            hospitalDataSet.bacsi.Rows[index].Delete();
        }

        private void ribbonButton6_Click(object sender, EventArgs e)
        {

        }
    }
}
